package com.yantong.service.impl;

import com.yantong.mapper.InformationTemplateMapper;
import com.yantong.pojo.InformationTemplate;
import com.yantong.service.InformationTemplateService;
import com.yantong.utils.PageUtils;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 订阅消息模版
 *
 * @author liaozhaogui-773104632@qq.com
 * @date 2020/11/12 10:29
 */
@Service
public class InformationTemplateServiceImpl implements InformationTemplateService {
	@Autowired
	private InformationTemplateMapper informationTemplateMapper;

	@Override
	public PageUtils<InformationTemplate> page(InformationTemplate informationTemplate, int offset, int limit) {
		PageUtils<InformationTemplate> pageUtils = new PageUtils<>();
		int total = informationTemplateMapper.queryCount(informationTemplate);
		if (total > 0) {
			pageUtils.setTotal(total);
			List<InformationTemplate> memberList = informationTemplateMapper.queryList(informationTemplate, new RowBounds(offset, limit));
			pageUtils.setRows(memberList);
		} else {
			pageUtils.setTotal(0);
			pageUtils.setRows(new ArrayList<>());
		}
		return pageUtils;
	}

	@Override
	public Long insert(InformationTemplate informationTemplate) {
		return informationTemplateMapper.insert(informationTemplate);
	}

	@Override
	public int update(InformationTemplate informationTemplate) {
		return informationTemplateMapper.update(informationTemplate);
	}

	@Override
	public InformationTemplate findDetail(Long id) {
		return informationTemplateMapper.findDetail(id);
	}
}
